package top.huxy.boot.model.dto;

import lombok.Data;
import top.huxy.boot.exception.RequestParamIllegalException;
import top.huxy.boot.util.RegexUtils;
import top.huxy.boot.util.StringUtils;
import top.huxy.boot.util.obj.ValidateAble;

/**
 * @author HuXY
 */
@Data
public class RegisterUserByEmailForm implements ValidateAble {
    private String username;
    private String password;
    private String yzm;
    private static int MIN_PWD_LENGTH = 6;
    private static int MAX_PWD_LENGTH = 60;

    @Override
    public void validate() {
        String temp;
        if ((temp = StringUtils.getEmptyParamName("username,pwd,yzm", username, password, yzm)) != null) {
            throw new RequestParamIllegalException("参数[" + temp + "]是必需的");
        }

        if (!RegexUtils.isEmail(username)&&!RegexUtils.isTelNumber(username)) {
            throw new RequestParamIllegalException("非法的用户名格式:" + username);
        }

        if (password.length() > MAX_PWD_LENGTH || password.length() < MIN_PWD_LENGTH) {
            throw new RequestParamIllegalException("密码长度区间为[6,60]");
        }
    }
}
